<?php
declare (strict_types = 1);

namespace app\listener;

use app\model\User;
use app\tool\Mongo;
use think\swoole\Websocket;

class SwWsClose
{
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event,Websocket $ws)
    {
        $fd = $ws->getSender();

        $mongo = new Mongo("8.130.18.175",27017,'jhx');
        $userQuery = [
            ['key'=>'fd','value'=>$fd]
        ];
        $updateArr = [
            ['key'=>'fd','value'=>0]
        ];
        $mongo->update('user',$userQuery,$updateArr);

        echo 'close';
    }
}
